define(['/js/config.js'], () => {
	require(['template','header','carts'],(template) => {
		class ShopCar {
			constructor() {
			    this.render()
				this.change()
			}
			
			render () {
				const cart = localStorage.getItem('cart')
				if (cart) {
					this.cart = JSON.parse(cart)
					$('.cartBox').html(template('cartBoxtemplate',{cart:this.cart}))
				} else {
					$('.cartMain').hide()
					$('.empty').show()
				}
			}
			
			change () {
				const _this = this
				$('.plus').on('click',function () {
					const id = Number($(this).parents('.amount_box').attr('data-id'))
					_this.cart = _this.cart.map( shop => {
						if (shop.id === id) shop.count ++
						return shop
					})
					localStorage.setItem('cart',JSON.stringify(_this.cart))
				})
			}
			
			
		}
		return new ShopCar()
	})
})